const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const HotModuleReplacementPlugin = require('webpack').HotModuleReplacementPlugin
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ProgressPlugin = require('progress-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const DefinePlugin = require('webpack').DefinePlugin
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
const Merge = require('webpack-merge')
const base = require('./webpack.common')

function resolve(dir) {
  return path.join(__dirname, dir)
}

const config = Merge(base, {
  mode: 'development',
  devtool: 'eval',
  entry: {
    app: [
      // resolve('../public/flexible.js'),
      resolve('/src/main.js')
    ]
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js',
    // publicPath: '/'
  },
  plugins: [
    new VueLoaderPlugin(),
    new DefinePlugin(
      {
        'process.env': {
          BASE_URL: '"/"',
          NODE_ENV: '"development"',
        }
      }
    ),
    // case-sensitive-paths
    new CaseSensitivePathsPlugin(),
    // friendly-errors
    new FriendlyErrorsPlugin(),
    // hmr
    new HotModuleReplacementPlugin(),
    // progress
    new ProgressPlugin(),
    // html
    new HtmlWebpackPlugin({
      template: resolve('/public/index.html')
    }),
    // copy
    new CopyWebpackPlugin(
      [
        {
          from: resolve('/public'),
          to: resolve('/dist'),
          toType: 'dir',
          ignore: [
            '.DS_Store'
          ]
        }
      ]
    )
  ],
  devServer: {
    hot: true,
    contentBase: resolve('/dist'),
    host: '0.0.0.0'
  },
  stats: 'errors-only'
})

module.exports = config
